home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-09-08 | 1.8 KB | 107 lines | [TEXT/PJMM] |
- program Mondrian;
- const
- kBaseResID = 128;
- kRandomUpperLimit = 32768;
-
-
- {--------------------------------> Randomize <---}
-
- function Randomize (range: INTEGER): INTEGER;
- var
- randomNumber: LONGINT;
- begin
- randomNumber := Random;
- randomNumber := abs(randomNumber);
-
- Randomize := (randomNumber * range) div kRandomUpperLimit;
- end;
-
-
- {--------------------------------> RandomPoint <---}
-
- procedure RandomPoint (var thePoint: Point);
- var
- window: WindowPtr;
- begin
- window := FrontWindow;
-
- thePoint.h := Randomize(window^.portRect.right - window^.portRect.left);
- thePoint.v := Randomize(window^.portRect.bottom - window^.portRect.top);
- end;
-
-
- {--------------------------------> DrawRandomIcon <---}
-
- procedure DrawRandomIcon (theIcon: CIconHandle);
- var
- p: Point;
- iconRect: Rect;
- begin
- RandomPoint(p);
-
- SetRect(iconRect, p.h, p.v, p.h + 32, p.v + 32);
- PlotCIcon(iconRect, theIcon);
- end;
-
-
- {--------------------------------> MainLoop <---}
-
- procedure MainLoop;
- var
- theIcon: CIconHandle;
- begin
- GetDateTime(randSeed);
-
- theIcon := GetCIcon(kBaseResID);
-
- if theIcon = nil then
- begin
- SysBeep(10);
- ExitToShell;
- end;
-
- while (not Button) do
- begin
- DrawRandomIcon(theIcon);
- end;
- end;
-
-
- {--------------------------------> WindowInit <---}
-
- procedure WindowInit;
- var
- window: WindowPtr;
- windowTitleH: StringHandle;
- begin
- window := GetNewWindow(kBaseResID, nil, WindowPtr(-1));
-
- if window = nil then
- begin
- SysBeep(10);
- ExitToShell;
- end;
-
- windowTitleH := GetString(kBaseResID);
-
- if windowTitleH = nil then
- begin
- SysBeep(10);
- ExitToShell;
- end;
-
- HLock(Handle(windowTitleH));
- SetWTitle(window, windowTitleH^^);
- HUnlock(Handle(windowTitleH));
-
- ShowWindow(window);
- SetPort(window);
- end;
-
-
- {--------------------------------> Mondrian <---}
-
- begin
- WindowInit;
- MainLoop;
- end.